<h1>Bienvenue dans l'administration</h1>
<div id="accueil" class="container">
    <div class="columns five">
        <div class="cadre_form ui-corner-all">
            <?php
            $lienAdresseCat = 'adresse';
            $adresseCat = modele_category::findByPermalien($lienAdresseCat);
            if($adresseCat===null){
                $adresseCat = new modele_category();
                $datas = array(
                    'title'=>$lienAdresseCat,
                    'lien'=>$lienAdresseCat,
                    'template'=>PWE::getDefaultTemplate()
                );
                $adresseCat->setDatas($datas);
                $adresseCat->save();
            }
            if($adresseCat->getNombrePublications()>0){
                $adresseListe = $adresseCat->getPublications(0, 1);
                $adresse = $adresseListe[0];
            }else{
                $adresse = new modele_publication();
                $adresse->setDatas(array(
                    'title'=>$lienAdresseCat,
                    'lien'=>$lienAdresseCat,
                    'content'=>'adresse du restaurant',
                    'category_id'=>$adresseCat->getId(),
                    'statut_id'=>2,
                    'template'=>PWE::getDefaultTemplate()
                ));
                $adresse->save();
            }
            ?>
            <h2 align="center">Adresse du restaurant <a href="?template=publication&action=update&modele_id=<?php echo $adresse->getId(); ?>" class="pwe-ui-btn" Title="Modifier"><span class="ui-icon ui-icon-pencil"></span></a></h2>
            <br/>
            <div align="center">
                <?php echo $adresse->getContent(); ?>
            </div>
        </div>
        <div class="cadre_form ui-corner-all">
            <?php
            $lienHorairesCat = 'horaires';
            $horairesCat = modele_category::findByPermalien($lienHorairesCat);
            if($horairesCat===null){
                $horairesCat = new modele_category();
                $datas = array(
                    'title'=>$lienHorairesCat,
                    'lien'=>$lienHorairesCat,
                    'template'=>PWE::getDefaultTemplate()
                );
                $horairesCat->setDatas($datas);
                $horairesCat->save();
            }
            if($horairesCat->getNombrePublications()>0){
                $horairesListe = $horairesCat->getPublications(0, 1);
                $horaires = $horairesListe[0];
            }else{
                $horaires = new modele_publication();
                $horaires->setDatas(array(
                    'title'=>$lienHorairesCat,
                    'lien'=>$lienHorairesCat,
                    'content'=>'horaires du restaurant',
                    'category_id'=>$horairesCat->getId(),
                    'statut_id'=>2,
                    'template'=>PWE::getDefaultTemplate()
                ));
                $horaires->save();
            }
            ?>
            <h2 align="center">Horaires d'ouverture <a href="?template=publication&action=update&modele_id=<?php echo $horaires->getId(); ?>" class="pwe-ui-btn" title="Modifier"><span class="ui-icon ui-icon-pencil"></span></a></h2>
            <br/>
            <div align="center">
                <?php echo $horaires->getContent(); ?>
            </div>
        </div>
    </div>
    <div class="columns five">
        <div class="cadre_form ui-corner-all">
            <?php
            $lienCadeauCat = 'idee-cadeau';
            $cadeauCat = modele_category::findByPermalien($lienCadeauCat);
            if($cadeauCat===null){
                $cadeauCat = new modele_category();
                $datas = array(
                    'title'=>$lienCadeauCat,
                    'lien'=>$lienCadeauCat,
                    'template'=>PWE::getDefaultTemplate()
                );
                $cadeauCat->setDatas($datas);
                $cadeauCat->save();
            }
            if($cadeauCat->getNombrePublications()>0){
                $cadeauListe = $cadeauCat->getPublications(0, 1);
                $cadeau = $cadeauListe[0];
            }else{
                $cadeau = new modele_publication();
                $cadeau->setDatas(array(
                    'title'=>$lienCadeauCat,
                    'lien'=>$lienCadeauCat,
                    'content'=>'idée cadeau',
                    'category_id'=>$cadeauCat->getId(),
                    'statut_id'=>2,
                    'template'=>PWE::getDefaultTemplate()
                ));
                $cadeau->save();
            }
            ?>
            <h2 align="center">Idée Cadeau <a href="?template=publication&action=update&modele_id=<?php echo $cadeau->getId(); ?>" class="pwe-ui-btn" title="Modifier"><span class="ui-icon ui-icon-pencil"></span></a></h2>
            <br/>
            <div>
                <?php echo $cadeau->getContent(); ?>
            </div>
        </div>
        <div class="cadre_form ui-corner-all">
            <?php
            $lienPromoCat = 'promos';
            $promoCat = modele_category::findByPermalien($lienPromoCat);
            if($promoCat===null){
                $promoCat = new modele_category();
                $datas = array(
                    'title'=>$lienPromoCat,
                    'lien'=>$lienPromoCat,
                    'template'=>PWE::getDefaultTemplate()
                );
                $promoCat->setDatas($datas);
                $promoCat->save();
            }
            if($promoCat->getNombrePublications()>0){
                $promoListe = $promoCat->getPublications(0, 1);
                $promo = $promoListe[0];
            }else{
                $promo = new modele_publication();
                $promo->setDatas(array(
                    'title'=>$lienPromoCat,
                    'lien'=>$lienPromoCat,
                    'content'=>'promo',
                    'category_id'=>$promoCat->getId(),
                    'statut_id'=>2,
                    'template'=>PWE::getDefaultTemplate()
                ));
                $promo->save();
            }
            ?>
            <h2 align="center">Promotions <a href="?template=publication&action=update&modele_id=<?php echo $promo->getId(); ?>" class="pwe-ui-btn" title="Modifier"><span class="ui-icon ui-icon-pencil"></span></a></h2>
            <br/>
            <div align="center">
                <?php echo $promo->getContent(); ?>
            </div>
        </div>
    </div>
    <div class="columns five">
        <div class="cadre_form ui-corner-all">
            <?php $menus = modele_category::findByPermalien('les-menus'); ?>
            <h2 align="center">Les menus <a href="<?php echo $menus->getUrl(); ?>" target="preview_site" class="pwe-ui-btn" title="Voir la page"><span class="ui-icon ui-icon-extlink"></span></a> <a href="?template=menus" class="pwe-ui-btn" class="Modifier"><span class="ui-icon ui-icon-pencil"></span></a></h2>
            <br/>
            <table class="liste ui-widget" align="center">
                <thead class="ui-widget-header">
                    <tr>
                        <th>Titre</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody class="liste-items-menu">
                    <?php foreach($menus->getPublications() as $i=>$menu): ?>
                    <tr class="ui-widget-content">
                        <td>
                            <span><?php echo $menu->getTitle(); ?></span><br/>
                        </td>
                        <td>
                            <a class="pwe-ui-btn" title="Voir" href="<?php echo $menu->getUrl(); ?>" target="_blank" ><span class="ui-icon ui-icon-extlink"></span></a>
                            <a class="pwe-ui-btn" title="Modifier" href="?template=menus&modele=publication&action=update&modele_id=<?php echo $menu->getId(); ?>"><span class="ui-icon ui-icon-pencil"></span></a>
                            <a href="?template=menus&modele=publication&action=delete&do=1&modele_id=<?php echo $menu->getId(); ?>" class="confirmAction pwe-ui-btn" title="Supprimer '<?php echo $menu->getTitle(); ?>'"><span class="ui-icon ui-icon-trash"></span></a>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
                <tfoot></tfoot>
            </table>
        </div>
        <div class="cadre_form ui-corner-all">
            <h2 align="center">Les cartes <a href="?template=cartes" class="pwe-ui-btn" title="Modifier"><span class="ui-icon ui-icon-pencil"></span></a></h2>
            <br/>
            <?php $menus = modele_category::findByPermalien('la-carte'); ?>
            <table class="liste ui-widget" align="center">
                <thead class="ui-widget-header">
                    <tr>
                        <th>Titre</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody class="liste-items-menu">
                    <?php foreach($menus->getChild() as $i=>$carte): ?>
                    <tr class="ui-widget-content">
                        <td>
                            <span><?php echo $carte->getTitle(); ?></span><br/>
                        </td>
                        <td>
                            <a class="pwe-ui-btn" title="Voir" href="<?php echo $carte->getUrl(); ?>" target="_blank" ><span class="ui-icon ui-icon-extlink"></span></a>
                            <a class="pwe-ui-btn" title="Modifier" href="?template=edit-carte&category_id=<?php echo $carte->getId(); ?>"><span class="ui-icon ui-icon-pencil"></span></a>
                            <a href="?template=cartes&modele=category&action=delete&do=1&modele_id=<?php echo $carte->getId(); ?>" class="confirmAction pwe-ui-btn" title="Supprimer '<?php echo $carte->getTitle(); ?>'"><span class="ui-icon ui-icon-trash"></span></a>    
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
                <tfoot></tfoot>
            </table>
        </div>
    </div>
</div>